//
//  UserModel.m
//  SoccerLottery
//
//  Created by chuanshuangzhang chuan shuang on 15/12/25.
//  Copyright © 2015年 chuanshuangzhang. All rights reserved.
//

#import "UserModel.h"

@interface UserModel ()

@property (nonatomic,readwrite) NSString *_coins;

@end

@implementation UserModel

SYNTHESIZE_SINGLETON_FOR_CLASS(UserModel)

-(NSString *)coin
{
    NSString *coins;
    if(self.phone.length <11){
        coins = [self getLocalCoins];
    }else {
        coins = __coins;
    }
    return coins;
}
- (NSString *)getLocalCoins
{
    NSString *coins = [[NSUserDefaults standardUserDefaults] objectForKey:@"COINS"];
    if(coins.length <=0)
    {
        coins = @"0";
    }
    return coins;
}

- (void)setCoin:(NSString *)coin
{
    if(self.phone.length <11){
        [[NSUserDefaults standardUserDefaults] setObject:coin forKey:@"COINS"];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
    __coins = coin;
}

- (void)clearLocalCoins
{
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"COINS"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}
- (void)clean
{
    self.userId = @"";
    self.phone = @"";
    self.userName = @"";
    self.password = @"";
    self.imgID = @"";
    self.coin = @"";
}
@end
